import { scheduleJob } from "node-schedule";
import fse from "fs-extra";
import { UPLOAD_PATH } from "../const/index.js";

export const everyDayTask = (task) => {
  return scheduleJob("0 0 * * *", task);
};

export const clearUploadsContentSchedule = () => {
  everyDayTask(async (_fireDate) => {
    const fileList = await fse.readdir(UPLOAD_PATH);
    for (const file of fileList) {
      fse.remove(`${UPLOAD_PATH}/${file}`);
    }
  });
};
